  var $_GET=(function(){var d=window.document.location.href.toString();var c=d.split("?");if(typeof(c[1])=="string"){c=c[1].split("&");var b={};for(var e in c){var a=c[e].split("=");b[a[0]]=a[1]}return b}else{return false}})();
  var openid = '';
  function wxtools(o) {
		
      o = $.extend({
          mode: 'none',
          url: location.href,
          wxstr: o.wxstr,
          wxdesc:o.wxdesc,
          shareimg:o.shareimg,
          shareurl: location.href
      }, o || {});
      var t = function () {
            var t = navigator.userAgent.toLowerCase();
            return "micromessenger" == t.match(/MicroMessenger/i) ? !0 : !1
      }
      var token = function(){
      	//console.log(o);
        //if(!t()){return false;}
        var e = window.localStorage;
        //本地存储是否存在
        //跳转取openid
        if(localStorage.getItem("ln_openid")){window.openid = localStorage.getItem("ln_openid");}
        else{
        	window.openid = $_GET.openid ? (window.openid = $_GET.openid, e.setItem("ln_openid", window.openid)) : window.location.href = "http://.../asset/base/wechat/auth.php?mode="+o.mode+"&redirect="+o.url;//修改服务器域名
        }
        openid = window.openid;
        jssdk();
      }
      
      var jssdk = function(){
      		if(!t()){return false;}
					//alert(wxsignature+' '+rawString);
					wx.config({
						debug: false,
						appId: wxappId,
						timestamp: wxtimestamp,
						nonceStr: wxnonceStr,
						signature: wxsignature,
						jsApiList: [
						   'onMenuShareTimeline','onMenuShareAppMessage'
						],
				    success: function (res) {
				      alert("检测通过：" +JSON.stringify(res));
				    },
				    fail: function(res) {
				        alert("检测失败：" +JSON.stringify(res));
				    },
				    complete: function(res) {
				       alert("检测结束");
				    }
					});
					wx.error(function () {
							//alert('error config');
					}) 
					wx.ready(function () {
						//alert('ready',o.shareurl);
							// 在这里调用 API
						wx.onMenuShareTimeline({			//朋友圈
							title: o.wxstr, // 分享标题
							link: o.shareurl, // 分享链接
							imgUrl: o.shareimg, // 分享图标
							success: function () { 
								// 用户确认分享后执行的回调函数
							},
							cancel: function () { 
								// 用户取消分享后执行的回调函数
							}
						});
						wx.onMenuShareAppMessage({			//好友
							title: o.wxstr, // 分享标题
							desc: o.wxdesc, // 分享描述
							link: o.shareurl, // 分享链接
							imgUrl: o.shareimg, // 分享图标
							type: '', // 分享类型,music、video或link，不填默认为link
							dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
							success: function () { 
								// 用户确认分享后执行的回调函数
							},
							cancel: function () { 
								// 用户取消分享后执行的回调函数
							}
						});
					});
		
      }
      return {
      		init:function(){
      			token();	
      		},
      		initjs:function(o){
      			jssdk();
      		}
      };
};
